package com.ztman.rxjava.view.activity;

import android.Manifest;
import android.support.annotation.NonNull;
import android.view.View;

import com.lypeer.fcpermission.FcPermissions;
import com.lypeer.fcpermission.impl.FcPermissionsCallbacks;
import com.ztman.rxjava.R;
import com.ztman.rxjava.model.baseEntity.BaseRxBusEvent;
import com.ztman.rxjava.mvp.presenter.ActivityPresenter;
import com.ztman.rxjava.mvp.viewProxy.MainActivityProxy;

import java.util.List;

public class MainActivity extends ActivityPresenter<MainActivityProxy> implements FcPermissionsCallbacks, View.OnClickListener{

    @Override
    protected Class<MainActivityProxy> getPresenterClass() {
        return MainActivityProxy.class;
    }

    @Override
    protected void initData() {
        atyPresenter.setOnClickListener(this, R.id.tPermission);
    }

    @Override
    protected void initView() {
        atyPresenter.register(this);
    }

    @Override
    protected void receiveRxBuxCommanders(BaseRxBusEvent baseRxBusEvent) {

    }


    @Override
    public void onClick(View v) {
        //申请相机拍照权限
        requestPermission();
    }



    public void requestPermission(){
        //权限参数是一个数组，也就是说可以一次申请多个权限；简单方便
        FcPermissions.requestPermissions(this , "申请相机拍照权限" , FcPermissions.REQ_PER_CODE , Manifest.permission.CAMERA);
    }

    /**
     * 功能：同意申请权限
     * @param i
     * @param list
     */
    @Override
    public void onPermissionsGranted(int i, List<String> list) {
        atyPresenter.showToastShort("同意权限申请操作~");
    }

    /**
     * 功能：拒绝申请权限
     * @param i
     * @param list
     */
    @Override
    public void onPermissionsDenied(int i, List<String> list) {
        atyPresenter.showToastShort("拒绝权限申请操作~");
    }

    /**
     * 功能：申请权限:Caller must be an Activity or a Fragment.
     * @param requestCode
     * @param permissions
     * @param grantResults
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        FcPermissions.onRequestPermissionsResult(requestCode , permissions , grantResults , this);
    }


}
